using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCatchSwordState : PlayerState
{
    public GameObject Sword;

    public PlayerCatchSwordState(Player player, StateMachine<PlayerState> stateMachine, string animBoolName) : base(player, stateMachine, animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        if (Sword != null)
        {
            float swordDir = Sword.transform.position.x - player.transform.position.x;
            if (!Mathf.Approximately(swordDir, 0f))
            {
                swordDir = swordDir / Mathf.Abs(swordDir);
                player.SetVelocity(swordDir, player.YVelocity, false);
                if (swordDir * player.facingDir < 0)
                {
                    player.Flip();
                }
            }
        }
        
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();
        if (triggerCalled)
        {
            stateMachine.ChangeState(player.idleState);
        }
    }
}
